import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 递归求解汉诺塔问题
 * User: 15085202591
 * Date: 2022-11-04
 * Time: 15:06
 */
public class Hanota {
    private static void hanota(int n,char pos1,char pos2,char pos3){
        if(n == 1){
            move(pos1,pos3);
            return;
        }
        hanota(n-1,pos1,pos3,pos2);
        move(pos1,pos3);
        hanota(n-1,pos2,pos1,pos3);
    }
    private static void move(char pos1,char pos2){
        System.out.println(pos1+"->"+pos2+" ");
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("输入盘子个数：");
        while (sc.hasNextInt()){
            int n = sc.nextInt();
            /**
             * n
             * pos1  起始位置
             * pos2  中转位置
             *pos3   目的位置
             */
            hanota(n,'A','B','C');
            System.out.println();
            System.out.print("输入盘子个数：");
        }
    }
}
